<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>办公系统 - 基础表格</title>
    <meta name="keywords" content="办公系统">
    <meta name="description" content="办公系统">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/select/bootstrap-select.min.css" rel="stylesheet">
    <link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>员工管理<small>>添加信息</small></h5>
                </div>
                <div class="ibox-content">
                    <form id="employeeForm"  method="post" action="${pageContext.request.contextPath}/emp/updateEmployeeByEid" enctype="multipart/form-data" class="form-horizontal">
                        <div class="row">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">姓名</label>
                                <div class="col-sm-3">
                                    <input type="hidden" name="eid" id="eid">
                                    <input name="ename" id="ename" type="text" class="form-control input-sm">
                                </div>
                                <label class="col-sm-2 col-sm-offset-1 control-label">用户名</label>
                                <div class="col-sm-3">
                                    <input name="username" id="username" type="text" class="form-control input-sm">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">密码</label>
                                <div class="col-sm-3">
                                    <input name="password" type="password" class="form-control input-sm">
                                </div>
                                <label class="col-sm-2 col-sm-offset-1 control-label">性别</label>
                                <div class="col-sm-3">
                                    <select name="esex">
                                        <option value="男" id="opt1">男</option>
                                        <option value="女" id="opt2">女</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">身份证号码</label>
                                <div class="col-sm-3">
                                    <input name="pnum" id="pnum" type="text" class="form-control input-sm">
                                </div>
                                <label class="col-sm-2 col-sm-offset-1 control-label">联系电话</label>
                                <div class="col-sm-3">
                                    <input name="telephone" id="telephone" type="text" class="form-control input-sm">
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <label class="col-sm-2 control-label">部门</label>
                            <div class="col-sm-3">
                                <select name="dfk" id="dfk">
                                    <option>请选择部门</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-offset-1 control-label">入职时间</label>
                                <div class="col-sm-3">
                                    <!--时间控件的id都不能改-->
                                    <input name="hiredate" id="start" class="laydate-icon form-control layer-date">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">年龄</label>
                                    <div class="col-sm-3">
                                        <input name="eage" id="eage" type="text" class="form-control input-sm">
                                    </div>
                                    <label class="col-sm-2 col-sm-offset-1 control-label">角色</label>
                                    <div class="col-sm-3">
                                        <select name="roleid" id="role">
                                            <option>请选择角色</option>

                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">头像:</label>
                                <div class="col-sm-9">
                                    <input type="file" name="uploadPic">
                                </div>

                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注</label>
                                <div class="col-sm-9">
                                    <textarea name="remark" id="remark" class="form-control"></textarea>
                                </div>

                            </div>
                        </div>

                        <div class="row">
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="row">
                            <div class="form-group">
                                <div class="col-sm-3 col-sm-offset-3 text-right">
                                    <button id="updateBtn" type="button" class="btn btn-primary"><i class="fa fa-save"></i> 更新内容</button>
                                </div>
                                <div class="col-sm-3">
                                    <a href="list-employee.jsp" class="btn btn-white"><i class="fa fa-reply"></i> 返回</a>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>




<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="js/plugins/select/bootstrap-select.min.js"></script>
<script src="js/plugins/layer/laydate/laydate.js"></script>
<script src="js/jquery.form.js"></script>
<script src="js/dateFormat.js"></script>

<script>
    $(document).ready(function() {
        // 设置按钮的样式
        $('.selectpicker').selectpicker('setStyle', 'btn-white');
        //初始化日期控件
        laydate({elem: "#start"});

        //根据eid查询该员工
        $.ajax({
            url:"${pageContext.request.contextPath}/emp/getEmployeeByEid",
            type:"post",
            data:{"eid":${param.eid}},
            dataType:"json",
            cache:false,
            success:function(rsd){
                $("#eid").val(rsd.employee.eid);
                $("#ename").val(rsd.employee.ename);
                $("#username").val(rsd.employee.username);
                $("#pnum").val(rsd.employee.pnum);
                $("#telephone").val(rsd.employee.telephone);
                $("#start").val(get_date(rsd.employee.hiredate));
                $("#eage").val(rsd.employee.eage);
                $("#remark").val(rsd.employee.remark);
                if(rsd.employee.esex=="男"){
                    $("#opt1").attr("checked",true);
                }else{
                    $("#opt2").attr("checked",true);
                }

                //查询所有的部门和所有的角色
                $.ajax({
                    url:"${pageContext.request.contextPath}/emp/getAllDeptAndRole",
                    type:"post",
                    dataType:"json",
                    cache:false,
                    success:function(rs){
                        var option="";
                        $.each(rs.depts,function(index,element){
                            if(rsd.employee.dfk==element.deptno){
                                option="<option value='"+element.deptno+"' selected>"+element.dname+"</option>";
                            }else{
                                option="<option value='"+element.deptno+"'>"+element.dname+"</option>";
                            }
                            $("#dfk").append(option);
                        });

                        $.each(rs.roles,function(index,element){
                            if(rsd.roleid==element.roleid){
                                option="<option value='"+element.roleid+"' selected>"+element.rolename+"</option>";
                            }else{
                                option="<option value='"+element.roleid+"'>"+element.rolename+"</option>";
                            }
                            $("#role").append(option);
                        });

                    }
                });




            }
        });



        //更新员工
        $("#updateBtn").click(function(){

            $("#employeeForm").ajaxForm();
            $("#employeeForm").ajaxSubmit(function (rs) {
                if(rs.status==200){
                    window.location="${pageContext.request.contextPath}/pages/list-employee.jsp";
                }else if(rs.status==400){
                    alert(rs.msg);
                }
            });
        });
    });


</script>
<!-- 修复日期控件长度-->
<link href="css/customer.css" rel="stylesheet">
</body>


</html>
